using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;

[CustomPropertyDrawer(typeof(SpineSkeletonAttribute))]
public class SpineSkeletonAttributeDrawer : PropertyDrawer
{
    public override VisualElement CreatePropertyGUI(SerializedProperty property)
    {
        if (property.propertyType != SerializedPropertyType.String)
        {
            Debug.Log($"SpineAnimation只对string类型有用：{property.name}");
            return new PropertyField();
        }
        
        SearchablePopup searchablePopup = new SearchablePopup();
        searchablePopup.label = property.displayName;

        List<string> bones = new List<string>();
        foreach (var bone in SpineTouchConfigSOEditor.ConfigSO.skeletonData.GetSkeletonData(true).Bones)
        {
            bones.Add(bone.Name);
        }
        searchablePopup.RegisterValueChangedCallback(evt =>
        {
            property.stringValue = evt.newValue;
            property.serializedObject.ApplyModifiedProperties();
        });
        
        searchablePopup.SetOptions(bones);
        searchablePopup.value = property.stringValue;
        
        return searchablePopup;
    }
}
